var ipt = document.querySelector(".ipt");
var list1 = document.querySelector(".list1");
var list1_img = document.querySelector('.list1_img');
var list2 = document.querySelector(".list2");
var list2_img = document.querySelector(".list2_img");

var done = document.querySelector(".done");
var del = document.querySelector(".del");
var video = document.querySelector(".video");

ipt.onkeyup = function(e){
	var text = ipt.value;
	if(e.keyCode === 13){
		if(text === ""){
			alert("请输入内容...");
		}else{
			var li = document.createElement('li');
			li.innerHTML = `
							<img src="images/2.png" class="list1_img">
							<span class = "list1_txt">
							${text}
							</span>
							`
			list1.appendChild(li);
			this.value = "";
		}
	}
}
list1.onclick = function(e){
	if(e.target.classList.contains('list1_img')){
		e.target.parentNode.remove();
		var item = e.target.parentNode.innerText;
		var cc = document.createElement('li');
		cc.innerHTML = `
						<img src="images/1.png" class="list2_img">
						<span class = "list2_txt">
						${item}
						</span>
						`
		list2.appendChild(cc);
	}
	if(list2.children.length != 0){
		done.style.display = "block";
	}
}

list2.onclick = function(e){
	if(e.target.classList.contains('list2_img')){
		e.target.parentNode.remove()
		var item = e.target.parentNode.innerText;
		var cc = document.createElement('li');
		console.log(cc);
		cc.innerHTML = `
						<img src="images/2.png" class="list1_img">
						<span class = "list1_txt">
						${item}
						</span>
						`
		list1.appendChild(cc);
		console.log(list1);
	}
	if(list2.children.length == 0){
		done.style.display = "none";
	}
}
del.onclick = function(){
	var lis = document.querySelectorAll('.list2>li');
	if(lis.length == 0){
		alert("没有删除元素");
	}else{
		var result = confirm(`共找到${lis.length}条数据是，是否要删除?`);
		if(result){
			for(var i=0; i<lis.length; i++){
				lis[i].remove()
				done.style.display = "none";
		}
		alert(`共删除${lis.length}条数据`);
	}
}
}	